import axios from 'axios';

const BASE_URL = 'http://localhost:8080/HotelOrders';

//查询所有酒店订单
export const listHotelOrders = async () => {
    try {
        const response = await axios.get(BASE_URL);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//增加订单
export const addHotelOrder = async (HotelOrder) => {
    try {
        const response = await axios.post(BASE_URL, HotelOrder, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error creating order:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//查询指定用户id的酒店订单
export const getHotelOrderByUid = async (Uid) => {
    try {
        const response = await axios.get(`${BASE_URL}/UserId/${Uid}`);
        return response.data;
    } catch (error) {
        console.error('Error creating order:', error.response ? error.response.data : error.message);
        throw error;
    }
};

export const updateHotelOrder = async (order) => {
    try {
        const response = await axios.put(BASE_URL, order, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error updating room:', error.response ? error.response.data : error.message);
        throw error;
    }
};

export const deleteHotelOrder = async (id) => {
    try {
        const response = await axios.delete(`${BASE_URL}/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error updating room:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//查询指定状态的酒店订单
export const getHotelOrderByStatus = async (status) => {
    try {
        const response = await axios.get(`${BASE_URL}/Status/${status}`);
        return response.data;
    } catch (error) {
        console.error('Error creating order:', error.response ? error.response.data : error.message);
        throw error;
    }
};